package com.shoe.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.shoe.mapper.UserAftersaleMapper;
import com.shoe.pojo.AdminAftersalePojo;
import com.shoe.service.UserAftersaleService;
import com.shoe.util.ResultUtil;
import com.shoe.vo.ResponseResult;
import com.shoe.vo.UserAftShowVo;
import com.shoe.vo.UserAftersaleVo;
import com.shoe.vo.UserCouponVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserAftersaleServiceImpl implements UserAftersaleService {

    @Autowired
    UserAftersaleMapper userAftersaleMapper;

    @Autowired
    ResultUtil resultUtil;

    @Override
    public ResponseResult selectUserAftersaleByCondition(Integer pageNum, Integer pageSize, Integer userId, String aftersaleSolve) {
        List<UserAftersaleVo> userAftersaleVoList = userAftersaleMapper.selectUserAftersaleByCondition(userId, aftersaleSolve);
        if (null != userAftersaleVoList && userAftersaleVoList.size() > 0) {
//            System.out.println("service -> " + userAftersaleVoList.toString());
            PageInfo<UserAftersaleVo> userAftersaleVoPageInfo = PageHelper.startPage(pageNum, pageSize).doSelectPageInfo(() -> {
                userAftersaleMapper.selectUserAftersaleByCondition(userId, aftersaleSolve);
            });
            return resultUtil.getResponseResult(0, "", userAftersaleVoList.size(), userAftersaleVoPageInfo);
        } else {
            return resultUtil.getResponseResult(2, "没有结果");
        }
    }

    @Override
    public UserAftShowVo selectUAftShow(Integer userId, Integer orderId) {
        return userAftersaleMapper.selectUAftShow(userId, orderId);
    }

    @Override
    public int addUAft(Integer orderId, String aftSaleSolve, String aftRequi, String nowDay) {
        return userAftersaleMapper.addUAft(orderId, aftSaleSolve, aftRequi, nowDay);
    }

    @Override
    public List<AdminAftersalePojo> selectUAftHave(Integer aftOrderId) {
        return userAftersaleMapper.selectUAftHave(aftOrderId);
    }
}